package cn.edu.dutir.lucene;

import java.io.IOException;

import org.apache.lucene.index.IndexReader;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;

public class LuceneIndexRecovery {
	private LuceneIndexRecovery() {
	};

	public static void main(String[] args) {
		String usage = "java cn.edu.dutir.unit.lucene.LuceneIndexDeleter <index_dir>";
		if (args.length == 0) {
			System.err.println("Usage: " + usage);
			System.exit(1);
		}
		try {
			Directory directory = FSDirectory.getDirectory(args[0], false);
			IndexReader reader = IndexReader.open(directory);

			recoveryAll(reader);

			reader.close();
			directory.close();

		} catch (Exception e) {
			System.out.println(" caught a " + e.getClass()
					+ "\n with message: " + e.getMessage());
		}
	}

	public static void recoveryAll(IndexReader reader) throws IOException {
		reader.undeleteAll();
	}
}
